<template>
<div class="add-agent">
  <dept-dailog
    :title="$t('config.agent.editDept')"
    :isShow="isEdit"
    :form="editForm"
    @close="closeDailog"
  ></dept-dailog>
</div>
</template>
<script>
  import { deepClone } from '@/utils/m7Utils'
  import DeptDailog from './DeptDailog'
  export default {
    name: 'EditDept',
    data () {
      return {
        submitForm: null
      }
    },
    props: {
      isEdit: Boolean,
      editForm: Object
    },
    components: {
      DeptDailog
    },
    methods: {
      closeDailog (data) {
        if (data.type === 'submit') {
          this.submitForm = deepClone(data.addForm)
          delete this.submitForm.prentsName
          this.$store.dispatch('updateDept', this.submitForm).then((res) => {
            if (res && res.success) {
              // this.$store.dispatch('updateCache', { type: 'depts', id: this.submitForm._id, data: res.dept })
              this.$emit('close', data)
              this.$message({
                message: this.$t('config.agent.modifyDeptSuccess'),
                type: 'success'
              })
            }
          })
        } else {
          this.$emit('close', data)
        }
      }
    }
  }
</script>

